/** @file    EntertainmentEvents.cpp
 *  @author  Alessandro Polo
 *  @version $Id: EntertainmentEvents.cpp 2804 2010-07-27 04:39:07Z alex $
 *  @brief
 * File containing implementation of classes defined in EntertainmentEvents.h
 * The header for this class can be found in EntertainmentEvents.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
 #include <framework/entertainment/EntertainmentEvents.h>

 #include <core/ObjectAllocator.h>
 #include <core/Variant.h>
 #include <core/List.h>
 #include <framework/entertainment/MediaList.h>
 #include <framework/entertainment/MediaTrack.h>


using namespace std;
namespace wosh {
 namespace entertainment {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::entertainment::PlayerAudioEvent_StateChanged, "wosh::Fact", 1.0, _static_PlayerAudioEvent_StateChanged )

PlayerAudioEvent_StateChanged::PlayerAudioEvent_StateChanged( int playstate, int volume, bool muted )
	: wosh::Fact(_Player_EVENT_PlayStateChanged ) {
	List* args = List::createFrom<Variant>( playstate, volume, muted );
	setData(args);
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

int PlayerAudioEvent_StateChanged::getPlayState() const {
	const Variant* var = getDataItem<Variant>(0);
	if ( var == NULL ) return _Player_STATE_Unknown;
	if ( var->isNumeric() ) return _Player_STATE_Unknown;
	return var->toInteger(_Player_STATE_Unknown);
 }

int PlayerAudioEvent_StateChanged::getVolume() const {
	const Variant* var = getDataItem<Variant>(1);
	if ( var == NULL ) return _Player_VOLUME_Unknown;
	if ( var->isNumeric() ) return _Player_VOLUME_Unknown;
	return var->toInteger(_Player_VOLUME_Unknown);
 }

int PlayerAudioEvent_StateChanged::getMuted() const {
	const Variant* var = getDataItem<Variant>(2);
	if ( var == NULL ) return 2;
	if ( !var->isBoolean() ) return 2;
	return var->toBoolean(false);
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

const char* PlayerAudioEvent_StateChanged::getPlayStateAsString( int playstate ) {
	switch(playstate) {
		case _Player_STATE_Idle:	return "Idle";
		case _Player_STATE_Playing:	return "Playing";
		case _Player_STATE_Paused:	return "Paused";
		default:					return "Unknown";
	 }
 }

int PlayerAudioEvent_StateChanged::getPlayStateFromString( const char* playstate ) {
	if ( playstate == NULL ) return _Player_STATE_Unknown;
	if ( strcmp(playstate, "Idle") == 0 ) return _Player_STATE_Idle;
	if ( strcmp(playstate, "Playing") == 0 ) return _Player_STATE_Playing;
	if ( strcmp(playstate, "Paused") == 0 ) return _Player_STATE_Paused;
	return _Player_STATE_Unknown;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::entertainment::PlayerAudioEvent_MediaTrackChanged, "wosh::Fact", 1.0, _static_PlayerAudioEvent_MediaTrackChanged )

PlayerAudioEvent_MediaTrackChanged::PlayerAudioEvent_MediaTrackChanged( const MediaTrack* track )
	: wosh::Fact(_Player_EVENT_MediaTrackChanged ) {
	if ( track != NULL )
		setData( track->clone() );
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::entertainment::PlayerAudioEvent_MediaListChanged, "wosh::Fact", 1.0, _static_PlayerAudioEvent_MediaListChanged )

PlayerAudioEvent_MediaListChanged::PlayerAudioEvent_MediaListChanged( const MediaList* list )
	: wosh::Fact(_Player_EVENT_MediaListChanged ) {
	if ( list != NULL )
		setData( list->clone() );
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 }; // namespace entertainment
}; // namespace wosh
